# coding:utf-8
'''
Created on 2015年6月30日

@author: Emrys
'''
import time
from threading import Thread

# 简单的定义线程的方法


def countdown(n):
    while n > 0:
        print('T-minus', n)
        n -= 1
        time.sleep(5)


def RunCountDown():
    t = Thread(target=countdown, args=(10,))
    t.start()

#
# 使用类封装相关的方法


class CountdownTask:

    def __init__(self):
        self._running = True

    def terminate(self):
        self._running = False

    def run(self, n):
        while self._running and n > 0:
            print('T-minus', n)
            n -= 1
            time.sleep(0.5)


def RunCountdownTask():
    c = CountdownTask()
    t = Thread(target=c.run, args=(10,))
    t.start()

#
# 继承线程类的类


class CountdownThread(Thread):

    def __init__(self, n):
        super().__init__()
        self.n = n

    def run(self):
        while self.n > 0:
            print('T-minus', self.n)
            self.n -= 1
            time.sleep(0.5)


def RunCountdownThread():
    CountdownThread(5).start()


if __name__ == "__main__":
    RunCountdownThread()
